﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RVBike
{
    class PathUtility : Singleton<PathUtility>
    {
        public PathUtility(string rootDir)
        {
            RootDir = rootDir;
            ResourcesDir = RootDir + "Resources\\";
            MoviesDir = RootDir + "Movies\\";
            LanguagesDir = RootDir + "Languages\\";
            CharactersDir = RootDir + "Characters\\";
            SavesDir = RootDir;
        }

        #region Accessors
        public string RootDir { get; set; }
        public string ResourcesDir { get; set; }
        public string MoviesDir { get; set; }
        public string LanguagesDir { get; set; }
        public string CharactersDir { get; set; }
        public string SavesDir { get; set; }
        #endregion

        #region Helper functions
        public static string Normalize(string path)
        {
            /**
             * Path normalization
             * 
             * Applying following rules to path :
             *   - Replace '/' with '\\'
             *   - Terminate with '\'
             *   - Trim space from both side
             */
            string temp = string.Copy(path);
            // Replace '/' with '\\'
            temp = temp.Replace('/', '\\');

            // Trim start
            temp.TrimStart(' ');

            // Trim end
            temp.TrimEnd(new char[]{'\\', ' '});

            // Appending '\\' at the end
            temp += '\\';

            return temp;
        }
        #endregion
    }
}
